<?php

namespace App\Http\Controllers\api;

use App\Libraries\Payment\WechatPay\WechatPayPayment;
use App\Models\User;
use App\Services\Withdraw\UserWithdrawService;
use Illuminate\Http\Request;

class UserWithdrawController extends BaseController
{
    public function apply(Request $request)
    {
        $wid = $request->post('wid');
        try {
            $withdraw = UserWithdrawService::apply(auth('jwt')->user(), $wid);

            if ($withdraw['status'] == 'pending') {
                return $this->success($withdraw, '提现已提交');
            } else {
                return $this->success($withdraw, '提现成功');
            }
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    public function cancel(Request $request){

        WechatPayPayment::cancel();
    }
}
